package com.mdlib.helper.ui;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.util.Log;

import com.mdlib.helper.module.account.activities.BindPhoneActivity;
import com.mdlib.helper.module.send.profile.activitys.VoiceAnnouncementActivity;
import com.mdlib.helper.ui.dialog.LoginRunDialogFragment;
import com.ljlib.core.app.AppManager;
import com.mdlib.helper.common.ContentType;
import com.mdlib.helper.model.entity.OneKeyServiceEntity;
import com.mdlib.helper.model.entity.OrderEntity;
import com.mdlib.helper.model.entity.OrderIdInfo;
import com.mdlib.helper.model.entity.SelectEntity;
import com.mdlib.helper.model.entity.ServiceMoney;
import com.mdlib.helper.model.entity.ShareEntity;
import com.mdlib.helper.model.entity.VoucherEntity;
import com.mdlib.helper.model.entity.WebViewEntity;
import com.mdlib.helper.module.account.activities.ForgetPwdActivity;
import com.mdlib.helper.module.account.activities.LoginActivity;
import com.mdlib.helper.module.location.MapActivity;
import com.mdlib.helper.module.run.order.activitys.RunshVicinityActivity;
import com.mdlib.helper.module.run.order.activitys.RushOrderDetailsActivity;
import com.mdlib.helper.module.run.profile.activitys.RushBalanceActivity;
import com.mdlib.helper.module.run.profile.activitys.RushMessageActivity;
import com.mdlib.helper.module.run.profile.activitys.RushShareActivity;
import com.mdlib.helper.module.run.profile.activitys.SerViceStartActivity;
import com.mdlib.helper.module.send.order.activitys.AegcyActivity;
import com.mdlib.helper.module.send.order.activitys.CityActivity;
import com.mdlib.helper.module.send.order.activitys.MinnOrTakeActivity;
import com.mdlib.helper.module.send.order.activitys.ModifyPhoneActivity;
import com.mdlib.helper.module.send.order.activitys.OrderDetailsActivity;
import com.mdlib.helper.module.send.order.activitys.PayOrderActivity;
import com.mdlib.helper.module.send.order.activitys.SendVicinityActivity;
import com.mdlib.helper.module.send.profile.activitys.AddressActivity;
import com.mdlib.helper.module.send.profile.activitys.ApplyRunActivity;
import com.mdlib.helper.module.send.profile.activitys.BalanceActivity;
import com.mdlib.helper.module.send.profile.activitys.MessageActivity;
import com.mdlib.helper.module.send.profile.activitys.ProblemActivity;
import com.mdlib.helper.module.send.profile.activitys.ProfileEditActivity;
import com.mdlib.helper.module.send.profile.activitys.SendBuyActivity;
import com.mdlib.helper.module.send.profile.activitys.SettingActivity;
import com.mdlib.helper.module.send.profile.activitys.ShareActivity;
import com.mdlib.helper.module.send.profile.activitys.VoucherActivity;
import com.mdlib.helper.module.web.WebActivity;
import com.mdlib.helper.ui.activity.MainActivity;
import com.mdlib.helper.ui.activity.WebViewActivity;
import com.mdlib.helper.ui.dialog.EvaluationRunManDialogFragment;
import com.mdlib.helper.ui.dialog.OrderDetailsAddMoneyDialog;
import com.mdlib.helper.ui.dialog.OutLoginDialogFragment;
import com.mdlib.helper.ui.dialog.PayModeDialogFragment;
import com.mdlib.helper.ui.dialog.SelectDialgoFragment;
import com.mdlib.helper.ui.dialog.ServiceMoneyDialogFragment;
import com.mdlib.helper.ui.dialog.ShareDialogFragment;
import com.mdlib.helper.ui.dialog.SuccessTimeDialogFragment;
import com.mdlib.helper.ui.dialog.VoucherDialogFragment;
import com.mdlib.helper.ui.dialog.ZoomDialogFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * 作者：HQY on 16/11/8 15:37
 * 邮箱：hqy_xz@126.com
 */

public class UIHelper {

    public static final String EXTRA_CONTENT_TYPE = "extra_content_type";

    public static final String EXTRA_PHONE_NUM = "extra_phone_num";

    public static final String MAP_TYPE = "map_type";
    public static final String MAP_TYPE_ONE = "1";
    public static final String MAP_TYPE_TWO = "2";
    public static final String MAP_TYPE_THREE = "3";

    public static final String ADDRESS_RELATE = "address_relate";

    public static final String ADDRESS_TYPE_ONE = "1";
    public static final String ADDRESS_TYPE_TWO = "2";

    public static final String MONEY_RELATE_TYPE = "money_relate_type";

    public static final String BUDGET = "budget";

    public static final String WITHDRAWAL = "withdrawal";

    public static final String MONEY = "money";

    public static final String PHONE = "phone";
    public static final String CODE = "code";
    public static final String WEBVIEW = "webview";

    public static final String ORDER = "order";

    public static final String SERVICE_MONEY = "serivce_money";

    public static final String SUCCESS_TIME = "success_time";

    public static final String DIALOG_VOUCHER = "dialog_voucher";

    public static final String TYPE = "type";

    public static final String ACTIVITY_TYPE = "activity_type";

    public static final String ENTITY = "entity";


    public static final String MONNETONKA = "monnetonka";


    public static final String AGENCY = "agency";
    public static final String AGENCY_NAME = "agency_name";
    public static final String AGENCY_TYPE = "agency_type";
    public static final String AGENCY_TYPE_ONE = "1";
    public static final String AGENCY_TYPE_TWO = "2";
    public static final String BUY_TYPE = "buy_type";

    //消息推送类型
    public static final String PUSH_TYPE_WEB = "web";
    public static final String PUSH_TYPE_ORDER_DETAIL = "order_detail";
    public static final String PUSH_TYPE_ACCOUNT_BALANCE = "account_balance";
    public static final String PUSH_TYPE_INDEX = "index";
    public static final String PUSH_TYPE_HISTORY = "history";
    public static final String PUSH_TYPE_NOTICE_CENTER =  "notice_center";
    public static final String PUSH_TYPE_RUN_INDEX = "run_index";
    public static final String TAKE = "take";

    public static final String ADD_SERVICE_MONEY = "add_service_money";

    public static final String PAY_MODE = "pay_mode";


    public static final String EVALUATION = "evaluation";

    public static final String SHARE = "share";
    public static final String SELECT = "select";
    public static final String ORDERIDINFO = "orderidinfo";
    public static final String BALANCE = "1";
    public static final String WECHAT = "2";
    public static final String ALIPAY = "3";
    public static final String OTHER = "4";
    public static final String BUS_ID = "busid";


    public static final String URL = "url";


//    Activity


    /**
     * WEB界面
     *
     * @param context
     * @param title
     * @param url
     */
    public static void showWebPage(Context context, String title, String url) {
        Intent intent = WebActivity.newIntent(context, title, url);
        context.startActivity(intent);

    }

    /**
     * 绑定手机号
     *
     * @param context
     */
    public static void showBindPhonePage(Context context) {
        Intent intent = BindPhoneActivity.newIntent(context);
        context.startActivity(intent);
    }

    /**
     * 忘记密码
     *
     * @param context
     */
    public static void showForgetPwdPage(Context context) {
        Intent intent = ForgetPwdActivity.newIntent(context);
        context.startActivity(intent);
    }


    public static void showLogin(Activity activity) {
        Intent login = new Intent(activity, LoginActivity.class);
        activity.startActivity(login);
        AppManager.getAppManager().finishActivity(MainActivity.class);
        activity.finish();
    }

    public static void showMainPage(Activity activity) {
        Intent mainIntent = new Intent(activity, MainActivity.class);
        activity.startActivity(mainIntent);
        activity.finish();
    }

    public static void showMapPage(Activity activity, String type, String buyType) {
        Intent intent = MapActivity.newIntent(activity, "", "", type, buyType);
        activity.startActivityForResult(intent, MapActivity.REQUEST_ADDRESS_CODE);
    }
//
//    /**
//     * 登录界面关联跳转
//     *
//     * @param mContext
//     * @param contentType
//     */
//    public static void showLoginRelation(Context mContext, ContentType contentType) {
//        Intent intent = LoginRelationActivity.newIntent(mContext, contentType);
//        mContext.startActivity(intent);
//    }

    public static void showCity(Activity activity) {
        Intent intent = new Intent(activity, CityActivity.class);
        activity.startActivity(intent);
    }

    /**
     * 附近
     */
    public static void shwoSendVicinity(Activity activity) {
        Intent intent = new Intent(activity, SendVicinityActivity.class);
        activity.startActivity(intent);
    }


    /**
     * 首页关联跳转
     *
     * @param mContext
     * @param contentType
     */

    public static void showHomeRelationThree(Context mContext, ContentType contentType, String orderEntity) {
        Intent intent = OrderDetailsActivity.newIntent(mContext, contentType, orderEntity);
        mContext.startActivity(intent);
    }


    /**
     * 我的资料
     *
     * @param activity
     */
    public static void showProfileEdit(Activity activity) {
        Intent intent = new Intent(activity, ProfileEditActivity.class);
        activity.startActivity(intent);
    }

    /**
     * 申请跑男
     *
     * @param activity
     */
    public static void showRun(Activity activity) {
        Intent intent = new Intent(activity, ApplyRunActivity.class);
        activity.startActivity(intent);
    }

    /**
     * 代金券
     *
     * @param activity
     */
    public static void showVoucher(Activity activity) {
        Intent intent = new Intent(activity, VoucherActivity.class);
        activity.startActivity(intent);
    }

    /**
     * 修改手机号
     *
     * @param activity
     * @param phone
     */
    public static void showModifyPHone(Activity activity, String phone, String type) {
        Intent intent = ModifyPhoneActivity.newIntent(activity, phone, type);
        activity.startActivity(intent);
    }

    /**
     * 余额
     *
     * @param activity
     */
    public static void showBalance(Activity activity) {
        Intent intent = new Intent(activity, BalanceActivity.class);
        activity.startActivity(intent);
    }

    /**
     * 我的购买
     *
     * @param activity
     */
    public static void showMyBuy(Activity activity) {
        Intent intent = new Intent(activity, SendBuyActivity.class);
        activity.startActivity(intent);
    }

    /**
     * 常用地址
     *
     * @param activity
     */
    public static void showAddress(Activity activity, String type) {
        Intent intent = AddressActivity.newIntent(activity, type);
        activity.startActivity(intent);
    }

    /**
     * 派单-分享
     *
     * @param activity
     */
    public static void showShare(Activity activity) {
        Intent intent = new Intent(activity, ShareActivity.class);
        activity.startActivity(intent);
    }

    /**
     * 消息问题
     *
     * @param activity
     */
    public static void showMessage(Activity activity) {
        Intent intent = new Intent(activity, MessageActivity.class);
        activity.startActivity(intent);
    }

    /**
     * 常见问题
     *
     * @param activity
     */
    public static void showProblem(Activity activity) {
        Intent intent = new Intent(activity, ProblemActivity.class);
        activity.startActivity(intent);
    }

    /**
     * 设置
     *
     * @param activity
     */
    public static void showSet(Activity activity) {
        Intent intent = new Intent(activity, SettingActivity.class);
        activity.startActivity(intent);
    }
    /**
     * 设置
     *
     * @param activity
     */
    public static void showVoice(Activity activity) {
        Intent intent = new Intent(activity, VoiceAnnouncementActivity.class);
        activity.startActivity(intent);
    }
    /**
     * 代買或代送取
     *
     * @param activity
     * @param type
     */
    public static void showSendOrderOne(Activity activity, String type) {
        Intent intent = MinnOrTakeActivity.newIntent(activity, type);
        activity.startActivity(intent);

    }

    /**
     * 代办
     *
     * @param activity
     */
    public static void showAegency(Activity activity, OneKeyServiceEntity keyServiceEntity, String type) {
        Intent intent = AegcyActivity.newIntent(activity, keyServiceEntity, type);
        activity.startActivity(intent);
    }

    /**
     * 订单支付
     *
     * @param activity
     * @param idInfo
     */
    public static void showPayOrder(Activity activity, OrderIdInfo idInfo) {
        Intent intent = PayOrderActivity.newIntent(activity, idInfo);
        activity.startActivity(intent);
        activity.finish();
    }


// DialogFragment

    /**
     * 服务费
     *
     * @param activity
     */
    public static void showServiceMoney(FragmentActivity activity, ServiceMoney serviceMoney) {
        FragmentManager fm = activity.getSupportFragmentManager();
        Fragment fragment = fm.findFragmentByTag(SERVICE_MONEY);
        if (fragment == null) {
            DialogFragment dialog = ServiceMoneyDialogFragment.newInstance(serviceMoney);
            dialog.show(fm, SERVICE_MONEY);
        }
    }

    /**
     * 完成时间
     *
     * @param activity
     */
    public static void showSuccessTime(FragmentActivity activity) {
        FragmentManager fm = activity.getSupportFragmentManager();
        Fragment fragment = fm.findFragmentByTag(SUCCESS_TIME);
        if (fragment == null) {
            DialogFragment dialog = SuccessTimeDialogFragment.newInstance();
            dialog.show(fm, SUCCESS_TIME);
        }
    }

    /**
     * 优惠券
     *
     * @param activity
     */
    public static void showDialogVoucher(FragmentActivity activity, ArrayList<VoucherEntity> voucherEntities) {
        FragmentManager fm = activity.getSupportFragmentManager();
        Fragment fragment = fm.findFragmentByTag(DIALOG_VOUCHER);
        if (fragment == null) {
           DialogFragment dialog = VoucherDialogFragment.newInstance(voucherEntities);
            dialog.show(fm, DIALOG_VOUCHER);
        }
    }

    /**
     * 详情页加服务费
     *
     * @param activity
     */
    public static void showDialogAddServiceMoney(FragmentActivity activity, ServiceMoney serviceMoney, String busId) {
        FragmentManager fm = activity.getSupportFragmentManager();
        Fragment fragment = fm.findFragmentByTag(ADD_SERVICE_MONEY);
        if (fragment == null) {
            DialogFragment dialog = OrderDetailsAddMoneyDialog.newInstance(serviceMoney, busId);
            dialog.show(fm, ADD_SERVICE_MONEY);
        }
    }

    /**
     * 付款方式
     *
     * @param activity
     */
    public static void showDialogPayMode(FragmentActivity activity) {
        FragmentManager fm = activity.getSupportFragmentManager();
        Fragment fragment = fm.findFragmentByTag(PAY_MODE);
        if (fragment == null) {
            DialogFragment dialog = PayModeDialogFragment.newInstance();
            dialog.show(fm, PAY_MODE);
        }
    }

    /**
     * 付款方式
     *
     * @param activity
     */
    public static void showDialogEvaluation(FragmentActivity activity, OrderEntity orderEntity) {
        FragmentManager fm = activity.getSupportFragmentManager();
        Fragment fragment = fm.findFragmentByTag(EVALUATION);
        if (fragment == null) {
            DialogFragment dialog = EvaluationRunManDialogFragment.newInstance(orderEntity);
            dialog.show(fm, EVALUATION);
        }
    }

    /**
     * 分享
     *
     * @param activity
     */
    public static void showDialogShare(FragmentActivity activity, ShareEntity shareEntity) {
        FragmentManager fm = activity.getSupportFragmentManager();
        Fragment fragment = fm.findFragmentByTag(SHARE);
        if (fragment == null) {
            DialogFragment dialog = ShareDialogFragment.newInstance(shareEntity);
            dialog.show(fm, SHARE);
        }
    }

    /**
     * 选择
     *
     * @param activity
     * @param selectList
     * @param type
     */
    public static void showSelectList(FragmentActivity activity, List<SelectEntity> selectList, String type) {
        FragmentManager fm = activity.getSupportFragmentManager();
        Fragment fragment = fm.findFragmentByTag(SELECT);
        if (fragment == null) {
            DialogFragment dialog = SelectDialgoFragment.newInstance(selectList, type);
            dialog.show(fm, SELECT);
        }
    }

    //    跑客

    /**
     * 订单详情
     *
     * @param activity
     * @param busId
     */
    public static void showRushOrderDetails(Activity activity, String busId) {
        Intent intent = RushOrderDetailsActivity.newIntent(activity, busId);
        activity.startActivity(intent);
    }

    /**
     * 服务星级
     *
     * @param activity
     */
    public static void showRushServiceStart(Activity activity) {
        Intent intent = new Intent(activity, SerViceStartActivity.class);
        activity.startActivity(intent);
    }

    /**
     * 跑客余额
     *
     * @param activity
     */
    public static void showRushBalance(Activity activity) {
        Intent intent = new Intent(activity, RushBalanceActivity.class);
        activity.startActivity(intent);
    }

    /**
     * 跑客分享
     *
     * @param activity
     */
    public static void showRushShare(Activity activity) {
        Intent intent = new Intent(activity, RushShareActivity.class);
        activity.startActivity(intent);
    }

    public static void showRushMessage(Activity activity) {
        Intent intent = new Intent(activity, RushMessageActivity.class);
        activity.startActivity(intent);
    }

    public static void showRushVicinity(Activity activity) {
        Intent intent = new Intent(activity, RunshVicinityActivity.class);
        activity.startActivity(intent);
    }

    /**
     * 网页
     *
     * @param activity
     * @param webViewEntity
     */
    public static void showWeb(Activity activity, WebViewEntity webViewEntity) {
        Intent intent = WebViewActivity.newIntent(activity, webViewEntity);
        activity.startActivity(intent);
    }

    /**
     * 登陆申请跑客中
     *
     * @param activity
     */
    public static void showLoginRun(FragmentActivity activity) {
        FragmentManager fm = activity.getSupportFragmentManager();
        Fragment fragment = fm.findFragmentByTag(TYPE);
        if (fragment == null) {
            DialogFragment dialog = LoginRunDialogFragment.newInstance();
            dialog.show(fm, TYPE);
        }
    }

    /**
     * 被动退出
     *
     * @param activity
     */
    public static void showLoginOut(FragmentActivity activity) {
        FragmentManager fm = activity.getSupportFragmentManager();
        Fragment fragment = fm.findFragmentByTag(TYPE);
        if (fragment == null) {
            DialogFragment dialog = OutLoginDialogFragment.newInstance();
            dialog.show(fm, TYPE);
        }
    }

    public static void showPicZoom(FragmentActivity activity, String url) {
        FragmentManager fm = activity.getSupportFragmentManager();
        Fragment fragment = fm.findFragmentByTag(TYPE);
        if (fragment == null) {
            DialogFragment dialog = ZoomDialogFragment.newInstance(url);
            dialog.show(fm, TYPE);
        }
    }


}
